package crivia.ecp.carry.tableString;

public class TableColumnMethod {
	
	@Deprecated
	public TableColumnMethod(){}
	
	public TableColumnMethod(String method , Class<?> type, String... columns){
		if (null != method)
			this.method = method;
		if (null != type)
			this.type = type;
		for (String s : columns){
			if (s.startsWith("v:")){
				addValue(s.substring(2));
			} else {
				addColumn(s);
			}
		}
		if (columns.length == 1){
			addValue("?");
		}
		if (columns.length == 0){
			addValue("?");
			addValue("?");
		}
	}
	
	public TableColumnMethod(String method , Class<?> type, Object... columns){
		if (null != method)
			this.method = method;
		if (null != type)
			this.type = type;
		for (Object o : columns){
			String s = String.valueOf(o);
			if (s.startsWith("v:")){
				addValue(s.substring(2));
			} else {
				addColumn(s);
			}
		}
		if (columns.length == 1){
			addValue("?");
		}
		if (columns.length == 0){
			addValue("?");
			addValue("?");
		}
	}
	
	protected Class<?> type = this.getClass();
	
	protected String method = "execute";
	
	protected StringBuilder param;

	public Class<?> getType() {
		return type;
	}

	public void setType(Class<?> type) {
		this.type = type;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getParam() {
		if (null == this.param){
			this.param = new StringBuilder();
		}
		return param.toString();
	}

	public void setParam(String param) {
		this.param = new StringBuilder(param);
	}
	
	public void addValue(String value){
		if (null == this.param){
			this.param = new StringBuilder();
		} else {
			this.param.append("+");
		}
		this.param.append(value);
	}
	
	public void addColumn(String value){
		if (null == this.param){
			this.param = new StringBuilder();
		} else {
			this.param.append("+");
		}
		this.param.append("column:");
		this.param.append(value);
	}
	
	public String execute(String s, String params){
		return params;
	}
	
}
